const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const getLowestOfferListingsForSKU = {};
getLowestOfferListingsForSKU.generateOption = function(seller_id, mws_auth_token, marketplaceId, sellerSKU, itemCondition){
  let baseOption = {
    'Version': '2011-10-01',
    'Action': 'GetLowestPricedOffersForSKU',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'MarketplaceId': marketplaceId,
    'SellerSKU': sellerSKU,
    'ItemCondition': itemCondition
  };

  return baseOption;
};

getLowestOfferListingsForSKU._ = function(options) {
  if (!isProduction) {
    return amazonMws.products.searchFor(options);
  } else {
    console.error("bot not implemented!");
  }
};

getLowestOfferListingsForSKU.getLowestOfferListingsForSKU = function(seller_id, mws_auth_token, sellerSKU, itemCondition) {
  return this._(this.generateOption(seller_id, mws_auth_token, sellerSKU, itemCondition));
};

module.exports = getLowestOfferListingsForSKU;